package collection_job;

import collection.Point;

import java.util.ArrayList;
import java.util.Collection;

public class CollectionDemo2 {
    public static void main(String[] args) {
        Collection<String> a=new ArrayList<>();
        a.add("one");
        a.add("two");
        a.add("three");
        a.add("four");
        a.add("five");

        System.out.println("size:"+a.size());
        System.out.println("是否为空集:"+a.isEmpty());
        a.clear();
        System.out.println("集合已清空");
        a.add("one");
        a.add("two");
        a.add("three");
        a.add("four");
        a.add("five");

        String p=new String("four");
        boolean contains=a.contains(p);
        System.out.println("是否包含："+contains);

        a.remove(p);
        System.out.println(a);

        Collection<Point>cc=new ArrayList<>();
        Point pp=new Point(1,2);
        cc.add(pp);
        System.out.println("pp:"+pp);
        System.out.println("cc:"+cc);

        pp.setX(100);
        System.out.println("pp:"+pp);
        System.out.println("cc:"+cc);

        Collection<String> c1=new ArrayList<>();
        c1.add("java");
        c1.add("c++");
        c1.add(".net");
        System.out.println("c1:"+c1);

        Collection c2=new ArrayList();
        c2.add("android");
        c2.add("ios");
        c2.add("java");
        System.out.println("c2:"+c2);

        c1.addAll(c2);//将c2添加到c1中
        System.out.println("c1:"+c1);
        System.out.println("c2:"+c2);

        Collection c3=new ArrayList();
        c3.add("c++");
        c3.add("android");
        c3.add("php");
        System.out.println("c3:"+c3);

        boolean contains1=c1.contains(c3);
        System.out.println("是否包含："+contains1);

        c1.retainAll(c3);//c1仅保留共有元素 c3不变
        System.out.println("c1:"+c1);
        System.out.println("c3:"+c3);

        c1.removeAll(c3);//删除c1中，与c3共有元素 c3不变
        System.out.println("c1:"+c1);
        System.out.println("c3:"+c3);


    }
}
